﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System
{
    /// <summary>
    /// 表示事件总线
    /// </summary>
    /// <remarks>
    /// 提供事件总线的初衷是为了解耦分离数据传输过程中的事件传递<br/>
    /// 总线的实现是通用化设计的，后续接手的程序员小朋友，可以将其用于任意你想使用事件总线的地方
    /// </remarks>
    /// <typeparam name="TEventType">事件类型</typeparam>
    public interface IEventBus<TEventType>
    {
        /// <summary>
        /// 发布事件
        /// </summary>
        /// <param name="eventMessage">事件消息</param>
        void Publish<TEventData>(EventMessage<TEventType, TEventData> eventMessage);

        /// <summary>
        /// 异步订阅事件
        /// </summary>
        /// <param name="eventType">事件类型</param>
        /// <param name="handler">处理事件的委托</param>
        void Subscribe<TEventData>(TEventType eventType, Func<EventMessage<TEventType, TEventData>, Task> handler);

        /// <summary>
        /// 同步订阅事件
        /// </summary>
        /// <param name="eventType">事件类型</param>
        /// <param name="handler">处理事件的委托</param>
        void Subscribe<TEventData>(TEventType eventType, Action<EventMessage<TEventType, TEventData>> handler);
    }
}
